/*
 * SDL_event.c
 *
 *  Created on: Nov 29, 2020
 *      Author: ZKSWE Develop Team
 */

#include <stdlib.h>

#include "event/event.h"
#include "context/message.h"
#include "dev_gt911.h"

bool event_init() {

	printf("init event\n");
	GT911_Init();
	printf("init event end\n");
	return true;
}

void event_deinit() {

}

bool event_poll() {
	
	uint16_t x,y;
	uint8_t ret = GT911_Scan(&x,&y);
	if(ret == 0) return 0;
	#if 1
	msg_t m = { E_MSG_TYPE_TOUCHEVENT, E_TOUCH_DOWN, MAKEDWORD(x, y) };
	#else
	msg_t m = { E_MSG_TYPE_TOUCHEVENT, E_TOUCH_DOWN, MAKEDWORD(272-y, x) };
	#endif
	if (ret == 1) {
		m.param1 = E_TOUCH_DOWN;
	} else if (ret == 2) {
		m.param1 = E_TOUCH_MOVE;
	} else if (ret == 3) {
		m.param1 = E_TOUCH_UP;
	}
	message_enqueue(&m);

	return false;
}
